package com.shy.controller;

import com.github.pagehelper.PageInfo;
import com.shy.config.model.R;
import com.shy.config.query.ActivityList;
import com.shy.entity.Activity;
import com.shy.entity.ActivityRemark;
import com.shy.entity.User;
import com.shy.service.ActivityService;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/activity")
public class ActivityController {
    @Resource
    private ActivityService activityService;

    @ApiOperation("活动列表查询")
    @PreAuthorize("hasAuthority('activity:list')")
    @RequestMapping("/pageList")
    public R<PageInfo<Activity>> pageList(@RequestParam Integer current,
                                          @RequestParam(required = false, defaultValue = "10") Integer pageSize, ActivityList activityList) {
        PageInfo<Activity> pageInfo = activityService.queryActivityListByPage(current, pageSize, activityList);
        return R.success(pageInfo);
    }

    @ApiOperation("活动详情")
    @PreAuthorize("hasAuthority('activity:view')")
    @RequestMapping("/detail/{activityId}")
    public R<Activity> activityDetail(@PathVariable Integer activityId) {
        Activity activity = activityService.queryActivityById(activityId);
        return R.success(activity);
    }

    @ApiOperation("活动添加")
    @PreAuthorize("hasAuthority('activity:add')")
    @RequestMapping("/addActivity")
    public R<String> addActivity(@RequestBody Activity activity) {
        Boolean activitys = activityService.addActivity(activity);
        return activitys ? R.success(null) : R.failure("添加失败");
    }

    @ApiOperation("查询活动负责人")
    @RequestMapping("/ownerList")
    public R<List<User>> queryOwnerName() {
        List<User> userList = activityService.getResponsiblePersons();
        return R.success(userList);
    }

    @ApiOperation("编辑活动信息")
    @PreAuthorize("hasAuthority('activity:edit')")
    @PutMapping("/editActivity")
    public R<String> editActivity(@RequestBody Activity activity) {
        Boolean activitys = activityService.modifyActivity(activity);
        return R.HANDLE(activitys);
    }

    @ApiOperation("批量删除活动")
    @PreAuthorize("hasAuthority('activity:delete')")
    @DeleteMapping("/batchDelete/{activityIds}")
    public R<String> batchDelete(@PathVariable List<Integer> activityIds) {
        Boolean activitys = activityService.batchActivityDelete(activityIds);
        return activitys ? R.success(null) : R.failure("批量删除失败");
    }

    @ApiOperation("查询活动备注列表")
    @GetMapping("/remarkList/{activityId}")
    public R<List<Activity>> remarkList(@PathVariable Integer activityId) {
        List<Activity> remarkList = activityService.queryUserListById(activityId);
        return R.success(remarkList);
    }

    @ApiOperation("删除活动备注状态")
    @DeleteMapping("/deleteRemark/{activityRemarkId}")
    public R<String> deleteRemark(@PathVariable Integer activityRemarkId) {
        // 删除活动备注
        Boolean activityRemarks = activityService.deleteRemark(activityRemarkId);
        return R.HANDLE(activityRemarks);
    }
    /**
     * 添加活动备注
     */
    @ApiOperation("添加活动备注")
    @PostMapping("/addRemark")
    public R<String> addRemark(@RequestBody ActivityRemark activityRemark) {
        // 添加活动备注
        Boolean activityRemarks = activityService.addActivityRemarks(activityRemark);
        return activityRemarks?R.success(null):R.failure("添加活动备注失败");
    }
   @ApiOperation("查询活动列表")
    @GetMapping("/list")
    public R<List<Activity>> queryActivityList(){
        List<Activity> activityList = activityService.queryActivityList();
        return R.success(activityList);
    }
}
